﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Cherry.Agile.Framework
{
    /// <summary>
    /// 用于存储查询条件的单元
    /// 2014-05-31
    /// 谢韶光
    /// </summary>
    [DataContract]
    public class ConditionItem:BaseItem
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public ConditionItem()
        { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="field">字段</param>
        /// <param name="method">比较</param>
        /// <param name="val">值</param>
        public ConditionItem(string field, QueryMethod method, object val)
        {
            Field = field;
            Method = method;
            Value = val;
        }

        ///// <summary>
        ///// 字段
        ///// </summary>
        //[DataMember]
        //public string Field { get; set; }

        /// <summary>
        /// 查询方式，用于标记查询方式HtmlName中使用[]进行标识
        /// </summary>
        [DataMember]
        public QueryMethod Method { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        [DataMember]
        public object Value { get; set; }

        ///// <summary>
        ///// 前缀，用于标记作用域，HTMLName中使用()进行标识
        ///// </summary>
        //[DataMember]
        //public string Prefix { get; set; }

        /// <summary>
        /// 如果使用Or组合，则此组组合为一个Or序列
        /// </summary>
        [DataMember]
        public string OrGroup { get; set; }

        //public ConditionItem(string field, )
    }


    /// <summary>
    /// Html表单元素的检索方式
    /// </summary>
    public enum QueryMethod
    {
        /// <summary>
        /// 等于
        /// </summary>
        //[GlobalCode("=", OnlyAttribute = true)]
        Equal = 0,

        /// <summary>
        /// 小于
        /// </summary>
        //// [GlobalCode("<", OnlyAttribute = true)]
        LessThan = 1,

        /// <summary>
        /// 大于
        /// </summary>
        // [GlobalCode(">", OnlyAttribute = true)]
        GreaterThan = 2,

        /// <summary>
        /// 小于等于
        /// </summary>
        // [GlobalCode("<=", OnlyAttribute = true)]
        LessThanOrEqual = 3,

        /// <summary>
        /// 大于等于
        /// </summary>
        // [GlobalCode(">=", OnlyAttribute = true)]
        GreaterThanOrEqual = 4,

        /// <summary>
        /// Like
        /// </summary>
        // [GlobalCode("like", OnlyAttribute = true)]
        Like = 6,

        /// <summary>
        /// In
        /// </summary>
        // [GlobalCode("in", OnlyAttribute = true)]
        In = 7,

        /// <summary>
        /// 输入一个时间获取当前天的时间块操作, ToSql未实现，仅实现了IQueryable
        /// </summary>
        // [GlobalCode("between", OnlyAttribute = true)]
        DateBlock = 8,

        // [GlobalCode("<>", OnlyAttribute = true)]
        NotEqual = 9,


        // [GlobalCode("like", OnlyAttribute = true)]
        StartsWith = 10,

        // [GlobalCode("like", OnlyAttribute = true)]
        EndsWith = 11,

        /// <summary>
        /// 处理Like的问题
        /// </summary>
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        Contains = 12,

        /// <summary>
        /// 处理In的问题
        /// </summary>
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        StdIn = 13,

        /// <summary>
        /// 处理Datetime小于+23h59m59s999f的问题
        /// </summary>
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
        DateTimeLessThanOrEqual = 14
    }
}
